package com.cityp.controller;

import com.cityp.bean.ResultBean;
import com.cityp.bean.sceneAndTool;
import com.cityp.bean.scene;
import com.cityp.service.sceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/moduleManage")
public class sceneManageController {
    /**
     * 查看所有场景
     */
    @Autowired
    private sceneService sceneService;
    @RequestMapping(value = "/sceneView",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean viewAll(){
        List<scene> res = sceneService.viewAll();
        if (res==null) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("查询成功",res);
    }

    /**
     * 添加一个场景
     */
    @RequestMapping(value = "/addScene",method = RequestMethod.POST)
    public ResultBean addOne(@RequestBody scene Scene){
        int res=sceneService.addOne(Scene);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("添加成功",res);
    }

    /**
     * 删除一个场景
     */
    @RequestMapping(value = "/delScene",method =RequestMethod.GET)
    public ResultBean delOne(@RequestParam int id){
        int res=sceneService.delOne(id);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("删除成功",res);
    }

    /**
     * 修改一个场景
     */
    @RequestMapping(value = "/changeScene",method = RequestMethod.POST)
    public ResultBean changeScene(@RequestBody sceneAndTool sceneAndTool){
        int res=sceneService.changeOne(sceneAndTool.getId(),sceneAndTool.getType(),sceneAndTool.getPara());
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success( "修改成功",res);
    }
}
